package it.kion.util.ui.umenumanager2.views.decorator;

import it.kion.util.ui.umenumanager2.model.Item;
import it.kion.util.ui.umenumanager2.views.MenuManagerView;
import it.kion.util.ui.umenumanager2.views.TreeObject;
import it.kion.util.ui.umenumanager2.views.TreeParent;

import org.eclipse.jface.viewers.IDecorationContext;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelDecorator;
import org.eclipse.swt.graphics.Image;


public class MenuManagerLabelDecorator extends LabelDecorator implements ILabelDecorator {

	@Override
	public Image decorateImage(Image image, Object element, IDecorationContext context) {
		Image res = MenuManagerView.getImage("FOLDER");
		if(element instanceof TreeObject){
			TreeObject to = (TreeObject) element;
			Item item = (Item)to.getWrappedObj();
			if(item!=null){
				if(item.isMdd() && !item.isNewMdd()){					
					if(item.getWarnings().size()>0){
						res = MenuManagerView.getImage("MDD_WARN");
					} else {
						res = MenuManagerView.getImage("MDD");
					}
				} else 
				if(item.isNewMdd()){					
					if(item.getWarnings().size()>0){
						res = MenuManagerView.getImage("NEW_MDD_WARN");
					} else {
						res = MenuManagerView.getImage("NEW_MDD");
					}
				}
				else {
					res = MenuManagerView.getImage("ITEM");					
				}
			}
		}
		return res;
	}

	@Override
	public String decorateText(String text, Object element, IDecorationContext context) {
		String res = text;
		if (element instanceof TreeParent){
			res = res.toUpperCase();
		} else {
			TreeObject to = (TreeObject) element;
			Item item = (Item)to.getWrappedObj();
			String viewFileName = item.getView();
			if (viewFileName.endsWith(".jsf")) {
				item.setView(viewFileName.replace(".jsf", ".jsp"));
			}
		}
		return res;
	}

	@Override
	public boolean prepareDecoration(Object element, String originalText, IDecorationContext context) {
		// TODO Auto-generated method stub
		return false;
	}

	public Image decorateImage(Image image, Object element) {
		
		return null;
	}

	public String decorateText(String text, Object element) {
		// TODO Auto-generated method stub
		return null;
	}

	public void addListener(ILabelProviderListener listener) {
	// TODO Auto-generated method stub

	}

	public void dispose() {
	// TODO Auto-generated method stub

	}

	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
	// TODO Auto-generated method stub

	}

}
